package currency

import (
	"go_server/game_server/constants"
	"go_server/game_server/dataconfig/config_manager"
	"go_server/game_server/dataconfig/configpb"
)

// 与货币有关联的数据
type Currency_RelatedData struct {
	CurrencyId                 int32 //货币id
	Cid                        constants.ConstCurrency
	BuildId                    int32           //建筑id
	TransCurrency              map[int32]int32 //货币转货币
	TransAccelerateMillisecond int64           //货币转时间加速（秒）
}

func (c *Currency_RelatedData) set_value(cfg configpb.StcTableCurrency_SheetCurrency_7A6D5966) {
	c.TransCurrency = make(map[int32]int32)
	for i := 0; i < len(cfg.Transcur); i++ {
		val := cfg.Transcur[i].Value
		c.TransCurrency[val[0]] = val[1]
	}

	for i := 0; i < len(cfg.Transdata); i++ {
		val := cfg.Transdata[i].Value
		switch val[0] {
		case 0:
			{
				c.TransAccelerateMillisecond = int64(val[1] * 1000)
			}
		}
	}
}

var (
	all_currency_data map[int32]*Currency_RelatedData
)

func init() {
	all_currency_data = make(map[int32]*Currency_RelatedData)
}

// 获得指定货币关联数据
func GetCurrency(id int32) (*Currency_RelatedData, bool) {
	cid := constants.ConstCurrency(id)
	data, dok := all_currency_data[id]
	if cfg, ok := config_manager.GetConfigStcTableCurrency_SheetCurrency(id); ok {
		data = &Currency_RelatedData{CurrencyId: id, Cid: cid, BuildId: cfg.Buildid}
		data.set_value(cfg)
		all_currency_data[id] = data
	}
	return data, dok || data != nil
}
